



$mode_name, $module_name, *$args = ARGV


class Everest
    ModeInstall     = "install"
    ModeNew         = "new"
    ModeUpdate      = "update"
    ModeFind        = "find"
    ModeDelete      = "del"
    ModeList        = "ls"
    ModeClean       = "clean"

    
    TypeAction      = "action"
    TypeWidget      = "widget"
    TypeHTML        = "html"
    TypeCSS         = "css"
    TypeView        = "view"
    TypeCasePHP     = "case.php"
    TypeCasePage    = "case.page"
    
end


def project_path path, name
  File.join( File.expand_path(File.dirname(__FILE__)), '..', path, name )
end

#
def project_widget_path group, type
    g = group
    g = 'home' if not g
    gs = g[0].upcase

    group = ''
    if g == 'home' or gs == 'H'
        group = 'Home/'
    elsif g == 'admin' or gs == 'A'
        group = 'Admin/'
    elsif g == 'common' or gs == 'C'
        group = ''                 
    end

    path = case type
        when Everest::TypeWidget
            "Tpl/#{group}Widgets"
        when Everest::TypeHTML
            "Tpl/#{group}Widgets/thtml"
        when Everest::TypeCSS
            "Tpl/#{group}Themes/default/css"
        when Everest::TypeCasePHP
            "Lib/Action/#{group}Cases"
        when Everest::TypeCasePage
            "Tpl/#{group}Cases"
    end    
end

#
def project_view_path group, type
    g = group
    g = 'home' if not g
    gs = g[0].upcase

    group = ''
    if g == 'home' or gs == 'H'
        group = 'Home/'
    elsif g == 'admin' or gs == 'A'
        group = 'Admin/'
    elsif g == 'common' or gs == 'C'
        group = ''                 
    end

    path = case type
        when Everest::TypeView
            "Tpl/#{group}Views"
    end    

end


def file_content file_name
    f = File.new file_name, 'r'
    content = f.read
    f.close
    return content
end

# Read file content of **.rbt
def ruby_template file_name
    return file_content file_name
end

# Write file content into path/name
def create_file path, name, content
    new_file_name = project_path(path, name)

    if File.exists? new_file_name
        puts "File: '#{name}' Exists."
        return
    end

    file = File.new new_file_name, 'w'
    file.write content
    file.close
end



